<?php

class SearchController extends Controller
{
    //public $layout ='//layouts/column1';
    public function actionIndex()
    {
        $this->layout='//layouts/column1';
        $model = new Job('search');
        $model->unsetattributes();
        if (isset($_GET['Job']))
        {
            $model->attributes=$_GET['Job'];
            $this->render('index', array('model'=>$model));
        }
    }
    public function actionAdvanced()
    {
        $dataProvider=new CActiveDataProvider('Job',array(
            'pagination'=>array(
                'pageSize'=>10,
            ),
        ));
        $this->render('advanced',array(
            'dataProvider'=>$dataProvider,
        ));
    }
    public function actionAdvancedTemp()
    {
        if (isset($_POST["input-name"])){
            $name = $_POST["input-name"];
            $criteria=new CDbCriteria;
            $criteria->addSearchCondition('name', $name);
            if (isset($_POST["jobtype"])) {
                $jobtype = $_POST["jobtype"];
                $criteria->addCondition("subjobtype_id = $jobtype");
            }
            if (isset($_POST["jobstatus"]) && $_POST["jobstatus"] > 0) {
                $jobstatus = $_POST["jobstatus"];
                if ($jobstatus < 3){
                    $criteria->addCondition("status = $jobstatus");
                }else{
                    $jobstatus -= 2;
                    $criteria->addCondition("statuspost = $jobstatus");
                }
            }
            if (isset($_POST["minmonney"]) && $_POST["minmonney"] > 0){
                $min = $_POST["minmonney"];
                $criteria->join ="inner join tbl_budget b on b.id = budget_id ";
                $criteria->addCondition("b.minmoney = $min");
            }
            if (isset($_POST["maxmonney"]) && $_POST["maxmoney"] > 0 ){
                $min = $_POST["maxmonney"];
                $criteria->join ="inner join tbl_budget b on b.id = budget_id";
                $criteria->addCondition("b.maxmonney = $min");
            }
            if(isset($_POST["timeend"]) && $_POST["timeend"] > 0){
                $time = $_POST["timeend"];
                $criteria->addCondition("datediff(timeend,timepost) = $time");
            }
            $dataProvider=new CActiveDataProvider('Job',array(
                'pagination'=>array(
                    'pageSize'=>3,
                ),
                'criteria'=>$criteria,
        ));
            $this->renderPartial('updatesearch', array('model'=>$dataProvider));

        }
        
    }
}
?>